package com.example.miflysky.view;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

    private static final String TAG = MainActivity.class.getSimpleName();

    private static final int ITEM1 = Menu.FIRST + 1;
    private static final int ITEM2 = Menu.FIRST + 2;
    private static final int ITEM3 = Menu.FIRST + 3;
    private static final int ITEM4 = Menu.FIRST + 4;
    private static final int ITEM5 = Menu.FIRST + 5;

    private TextView mText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mText = (TextView)findViewById(R.id.text1);

        registerForContextMenu(mText);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        SubMenu file = menu.addSubMenu("文件");


        menu.add(0, ITEM1, 3, "打开");
        menu.add(0, ITEM2, 2, "关闭");
        menu.add(0, ITEM3, 3, "退出");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case ITEM1:
                setTitle("打开");
                break;
            case ITEM2:
                setTitle("关闭");
                break;
            case ITEM3:
                setTitle("退出");
                break;
            default:
                break;
        }
        return true;
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info){
        menu.add(0, ITEM1, 0, "红色");
        menu.add(0, ITEM2, 0, "绿色");
        menu.add(0, ITEM3, 0, "蓝色");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item){
        switch (item.getItemId()){
            case ITEM1:
                mText.setBackgroundColor(Color.RED);
                break;
            case ITEM2:
                mText.setBackgroundColor(Color.GREEN);
                break;
            case ITEM3:
                mText.setBackgroundColor(Color.BLUE);
                break;

        }

        return true;
    }


}